import { defineConfig } from 'vite';
import { pluginExposeRenderer } from './vite.base.config.mjs';
import vue from "@vitejs/plugin-vue";

import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';

/************************************* 路径配置 start ********************************/
import { resolve } from 'path' 
import { off } from 'process';
const pathResolve = (dir)=>{
  return resolve(__dirname, ".", dir)          
}
/************************************* 路径配置 end ********************************/


// https://vitejs.dev/config
export default defineConfig((env) => {
  /** @type {import('vite').ConfigEnv<'renderer'>} */
  const forgeEnv = env;
  const { root, mode, forgeConfigSelf } = forgeEnv;
  const name = forgeConfigSelf.name ?? '';

  /** @type {import('vite').UserConfig} */
  return {
    root,
    mode,
    base: './',
    build: {
      outDir: `.vite/renderer/${name}`,
      chunkSizeWarningLimit:1500,
      rollupOptions:{
        output:{
          manualChunks(id){
              if(id.includes('node_modules')){
                return id.toString().split('node_modules/')[1].split('/')[0].toString();
              }
          }
        }
      }
    },
    plugins: [
      pluginExposeRenderer(name),
      vue(),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ],
      }),
    ],
    
    resolve: {
      preserveSymlinks: true,
      alias: {
        'vue': 'vue/dist/vue.esm-bundler.js',
        'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
        '@': pathResolve("src/renderer")
      }
    },
    clearScreen: false,
  };
});
